<%@ page contentType="text/html;charset=UTF-8" %>
<%@include file="../../common/sessionValidate.jsp" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE HTML>
<html lang="UTF-8">
<head>
    <title>物业费收款账单</title>
    <%@ include file="../../common/meta.jsp" %>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta http-equiv="X-UA-Compatible" content="IE=9">
    <META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">
    <link rel="stylesheet" href="<%=basePath%>css/my-bootstrap.css" media="screen" id="tuserskin">
    <link rel="stylesheet" href="<%=basePath%>js/toastr/toastr.css">
    <link rel="stylesheet" href="<%=basePath%>css/bootstrapValidator.min.css">
    <link rel="stylesheet" href="<%=basePath%>css/font-awesome.min.css">
    <script type="text/javascript" src="<%= basePath %>js/jquery.cookie.js"></script>
</head>
<style>
    hr {
        margin-top: 1px;
        border-bottom: 1px solid #1BBC9B;
    }
</style>
<body>
<div>
    <div class="" style="margin-right:2px;padding-right:1px;">

        <!--------------------------查询条件表格  start------------------------------->
        <form class="form-horizontal" name="form1" id="form1">
            <!-- 查询面板 -->
            <div class="panel panel-primary" id="cxDiv">
                <!-- Default panel contents -->
                <div class="panel-heading  ">
                    <i class='icon-filter'></i>&nbsp;物业费收款账单查询内容
                    <span class="text-right pull-right">
        	<button type="button" class=" btn btn-success btn-xs img-rounded" onclick="Search(0)"><i
                    class="icon-search"></i>&nbsp;查询</button>&nbsp;
            <button type="reset" class=" btn btn-success btn-xs img-rounded"> <span class="icon-retweet"></span>&nbsp;重置</button>&nbsp;
            <button type="button" class=" btn btn-success btn-xs img-rounded" id="shButton">&nbsp;<span id="qhDiv"
                                                                                                        class="icon-chevron-up"></span>&nbsp;</button>
            <input type="hidden" name="biztype" id="biztype" value="wuye">
                     <input type="hidden" name="billtype" id="billtype" value="物业费">
                    <input type="hidden" name="sftype" id="sftype" value="收款">

        </span>
                </div>
                <div class="panel-body" id="shDiv" class="panel-collapse collapse in">
                    <div class="col-xs-3">
                        <div class="form-group">
                            <label class="control-label col-xs-5">账单号</label>
                            <div class="col-xs-7">
                                <input name="billno" type="text" class="form-control">
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-3">
                        <div class="form-group">
                            <label class="control-label col-xs-5">应付日期从</label>
                            <div class="col-xs-7">
                                <input name="startdate" id="startdate" type="text" class="form-control"
                                       onclick='SelectDate(this)' readonly='true'>
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-3 ">
                        <div class="form-group">
                            <label class="control-label col-xs-5">至</label>
                            <div class="col-xs-7">
                                <input name="enddate" id="enddate" type="text" class="form-control"
                                       onclick='SelectDate(this)' readonly='true'>
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-3">
                        <div class="form-group">
                            <label class="control-label col-xs-6"> 楼栋 </label>
                            <div class="col-xs-6">
                                <select id="ext2" name="ext2" onchange="getBuildingHouseList()"
                                        class="form-control">
                                    <option value="">---请选择---</option>
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-3">
                        <div class="form-group">
                            <label class="control-label col-xs-6"> 房号 </label>
                            <div class="col-xs-6">
                                <select id="ext3" name="ext3" class="form-control">
                                    <option value="">---请选择---</option>
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-3">
                        <div class="form-group">
                            <label class="control-label col-xs-6"> 业主/租客 </label>
                            <div class="col-xs-6">
                                <select id="ext1" name="ext1" onchange="getCompanyList()"
                                        class="form-control">
                                    <option value="">---全部---</option>
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-3">
                        <div class="form-group">
                            <label class="control-label col-xs-6"> 账单状态 </label>
                            <div class="col-xs-6">
                                <select id="status" name="status" class="form-control">
                                    <option value="">--全部--</option>
                                    <option value="待生效">待生效</option>
                                    <option value="已生效">已生效</option>
                                    <option value="已作废">已作废</option>
                                </select>
                            </div>
                        </div>
                    </div>
                    <!--
                    <div class="col-xs-3">
                        <div class="form-group">
                            <label class="control-label col-xs-6"> 账单类型 </label>
                            <div class="col-xs-6">
                                <select id="" name="billtype" onchange=""
                                        class="form-control">
                                    <option value="">--请选择--</option>
                                    <option value="水费">水费</option>
                                    <option value="电费">电费</option>
                                    <option value="租金">租金</option>
                                    <option value="物业费">物业费</option>
                                    <option value="公共能损耗">公共能损耗</option>
                                    <option value="其它能损耗">其它能损耗</option>
                                    <option value="装修押金">装修押金</option>
                                    <option value="停车费">停车费</option>
                                    <option value="车位费">车位费</option>
                                    <option value="垃圾清运费">垃圾清运费</option>
                                    <option value="楼道保洁费">楼道保洁费</option>
                                    <option value="其它">其它</option>
                                </select>
                            </div>
                        </div>
                    </div>-->
                </div>
            </div>
        </form>
        <!--------------------------查询条件表格end------------------------------------->

        <!--------------------------信息列表：带表格面板  start--------------------------------->
        <div class="panel panel-primary">
            <div class="panel-heading clearfix">
                <i class='icon-reorder'></i>&nbsp; 物业费收款账单数据列表&nbsp;&nbsp;&nbsp;&nbsp;<font color="red"> 注意： 账单金额 =
                每月物业费单价 * 面积 * 付款周期(月数)</font>
                <span class="text-right pull-right ">
                <a href="<%=basePath%>t_contract_bill/toT_contract_billCurd?oplx=add" class="text-danger"><i
                        class='icon-plus'></i>&nbsp;新增</a>&nbsp;&nbsp;&nbsp;&nbsp;
            <a href="#" onclick="toEdits()" class="text-danger"><i class='icon-pencil'>&nbsp;修改</i></a>&nbsp;&nbsp;&nbsp;&nbsp;
            <a href="#" onclick="toViews()" class="text-danger"><i class='icon-table'></i>&nbsp;查看</a>&nbsp;&nbsp;&nbsp;&nbsp;
            <a href="#" onclick="Search(0)" class="text-danger"><i class='icon-refresh'></i>&nbsp;刷新</a>&nbsp;&nbsp;&nbsp;&nbsp;
            <a href="#" onclick="doExport()" class="text-danger"><i class='icon-download'></i>&nbsp;导出</a>&nbsp;&nbsp;&nbsp;&nbsp;
            <a href="#" onclick="showOrHidden()" class="text-danger"><span id="fsDiv"
                                                                                      class='glyphicon glyphicon-resize-full'></span></a>
	     </span>
            </div>
            <div class="panel-body">
                <p>每页显示<select id="pageSize" class=" label-primary" onchange="Search(0)">
                    <option value="10">10</option>
                    <option value="20">20</option>
                    <option value="30">30</option>
                    <option value="50">50</option>
                    <option value="100">100</option>
                    <option value="500">500</option>
                </select>条记录，&nbsp;&nbsp;&nbsp;&nbsp;共有记录：<span id="totalCount" class="label label-primary">0</span>
                    条，总页数：<span id="totalPageNo" class="label label-primary">0</span>页。
                </p>
                <table id="grid" class="table table-condensed table-striped table-bordered table-hover" class="sortable"
                       cellpadding="0" cellspacing="0" border="0" class="display" width="100%">
                    <thead id="grid_head">
                    <tr>
                        <th onclick="" class="table-checkbox"><input class="group-checkable" name="batchSelectedAll"
                                                                     id="batchSelectedAll" type="checkbox"
                                                                     onclick="selectAll()"></th>
                        <th onclick="sortTableT.sort('grid',0,'String')"> 账单号</th>
                        <th onclick="sortTableT.sort('grid',0,'String')">业主/租客</th>
                        <th onclick="sortTableT.sort('grid',0,'String')">合同号</th>
                        <th onclick="sortTableT.sort('grid',0,'String')">楼栋</th>
                        <th onclick="sortTableT.sort('grid',0,'String')">房号</th>
                        <th onclick="sortTableT.sort('grid',0,'String')">收付款类型</th>

                        <th onclick="sortTableT.sort('grid',0,'String')">账单类型</th>
                        <th onclick="sortTableT.sort('grid',0,'String')">账单金额</th>
                        <th onclick="sortTableT.sort('grid',0,'String')"> 实收金额</th>
                        <th onclick="sortTableT.sort('grid',0,'String')"> 需收金额</th>
                        <th onclick="sortTableT.sort('grid',0,'String')"> 账期</th>
                        <th onclick="sortTableT.sort('grid',0,'String')"> 付款周期(月数)</th>
                        <th onclick="sortTableT.sort('grid',0,'String')"> 每月物业费单价(元/平方米)</th>
                        <th onclick="sortTableT.sort('grid',0,'String')"> 面积</th>

                        <th onclick="sortTableT.sort('grid',0,'String')"> 逾期状态</th>
                        <th onclick="sortTableT.sort('grid',0,'String')"> 应付日期</th>
                        <th onclick="sortTableT.sort('grid',0,'String')"> 账单状态</th>
                        <th onclick="sortTableT.sort('grid',0,'String')"> 结算状态</th>
                        <!-- <th onclick="sortTableT.sort('grid',0,'String')"> 生成时间</th> -->
                        <th style="width:150px">操作</th>
                    </tr>
                    </thead>
                    <tbody id="grid_body"></tbody>
                </table>
                <div class="paging-toolbar">
                    <ul class="pager" style='margin-bottom:5px;' id='grid_paging'></ul>
                </div>
            </div>
        </div>
        <!--------------------------信息列表：带表格面板 end------------------------------------>

    </div>
</body>
</html>

<script src="<%=basePath%>js/bootstrap.min.js"></script>
<!--<script src="<%=basePath%>js/jquery-1.10.2/jquery.min.js"></script>
<script type="text/javascript" src="js/bootstrapValidator.js"></script>-->
<script src="<%=basePath%>js/bootstrap-paginator.min.js"></script>
<script src="<%=basePath%>/js/respond.js"></script>
<script src="<%=basePath%>/js/html5.js"></script>
<script src="<%=basePath%>js/toastr/toastr.js"></script>
<script src="<%=basePath%>js/bootbox.js"></script>
<script src="<%=basePath%>js/jquery.validate.js"></script>
<!-- <script src="<%=basePath%>js/additional-methods.min.js"></script> -->
<script src="<%=basePath%>js/my-jquery-curd.js"></script>
<script src="<%= basePath %>js/tableSortTool.js"></script>
<script src="<%= basePath %>js/calendar.js"></script>
<!-- 导出excel-->
<script src="<%= basePath %>js/export/libs/FileSaver/FileSaver.min.js"></script>
<script src="<%= basePath %>js/export/tableExport.js"></script>

<script type="text/javascript">
    function doExport() {
        $('#grid').tableExport({
                fileName: '物业费收款账单数据',
                type: 'excel',
                ignoreColumn: [0,19],
                mso: {worksheetName: '物业费收款账单数据'}
            }
        );
    }

    //获取楼栋列表信息
    function getCompanyList() {
        var url = "<%=basePath%>t_company/getAllT_company?startIndex=0&pageSize=10000&time=" + Math.random();
        //$.ajaxSettings.async = false;    //在执行之前加(同步执行)
        $.getJSON(url, function (data) {
            var str = "";
            $.each(data.items, function (i, item) {
                str += "<option value='" + item.company_name + "'>" + item.company_name + "</option>";
            });//end each data;
            $("#ext1").append(str);
            //alert("str="+str);
        });//end getJSON;
    }

    //获取楼栋房源列表信息
    function getBuildingHouseList() {
        $("select[name='ext3']")[0].options.length = 0; //清空上一次初始化的值；
        var buildingname = $("select[name='ext2']").val();
        //alert("buildingname="+buildingname);
        if (buildingname != "") {
            var url = "<%=basePath%>t_building_house/getAllT_building_house?buildingtype=1&buildingname=" + buildingname + "&startIndex=0&pageSize=10000&time=" + Math.random();
            //$.ajaxSettings.async = false;    //在执行之前加(同步执行)
            $.getJSON(url, function (data) {
                var str = "<option value=''>---全部---</option>";
                $.each(data.items, function (i, item) {
                    str += "<option value='" + item.housename + "'>" + item.housename + "</option>";
                });//end each data;
                $("#ext3").append(str);
                //alert("str="+str);
            });//end getJSON;
        }
    }

    //获取楼栋列表信息
    function getBuildingList() {
        var url = "<%=basePath%>t_building/getAllT_building?buildingtype=1&startIndex=0&pageSize=10000&time=" + Math.random();
        $.ajaxSettings.async = false;    //在执行之前加(同步执行)
        $.getJSON(url, function (data) {
            var str = "";
            $.each(data.items, function (i, item) {
                str += "<option value='" + item.name + "'>" + item.name + "</option>";
            });//end each data;
            $("#ext2").append(str);
            //alert("str="+str);
        });//end getJSON;
    }

    $().ready(function () {
        getCompanyList();
        getBuildingList();

        //1、初始化数据显示
        Search(0);

        //2、隐藏或者显示
        $("#shButton").click(function () {
            $("#shDiv").toggle();
            $("#qhDiv").toggleClass("icon-chevron-up icon-chevron-down");
        });

    }) //end funciton read;

    //根据查询条件，查询列表数据并显示
    function Search(startIndex) {
        //var biztype = "<%= request.getParameter("biztype")%>";
        //$("#biztype").val(biztype);
        //document.getElementById("biztype").value = biztype ;
        //var sftype = "<%= request.getParameter("sftype")%>";
        //if(sftype==null||sftype==""){
        //    sftype = "收款";
        //}
        //$("#sftype").val(sftype);

        var pageSize = document.getElementById("pageSize").value;
        var condition = $("#form1").serialize();
        var url = "<%=basePath%>t_contract_bill/getAllT_contract_bill?startIndex=" + startIndex + "&pageSize=" + pageSize + "&" + condition + "&time=" + Math.random();
        //alert(url);
        $.getJSON(url, function (data) {
            //$("#pageSize").html(data.pageSize);
            $("#totalCount").html(data.totalCount);
            $("#totalPageNo").html(data.totalPageNo);
            $("#grid_body").html("");

            //1、表格行内容输出
            var zdjrTotal=0; //账单金额总
            var ssjeTotal=0; //实收金额总
            var xsjeTotal=0;  //需收金额总
            var zmjTotal=0; //总面积

            $.each(data.items, function (i, item) {
                zdjrTotal += item.totalprice;
                ssjeTotal += 0;
                xsjeTotal += item.totalprice;
                zmjTotal += parseFloat(item.area);

                var str = "<tr>";
                str += "<td><input class='checkboxes' name='batchSelected' id='batchSelected' type='checkbox' value='" + item.billid + "'></td>";
                str += "<td>" + doNull(item.billno) + "</td>";
                str += "<td>" + doNull(item.ext1) + "</td>";
                str += "<td>" + doNull(item.contractno) + "</td>";
                str += "<td>" + doNull(item.ext2) + "</td>";
                str += "<td>" + doNull(item.ext3) + "</td>";
                str += "<td>" + doNull(item.sftype) + "</td>";

                str += "<td>" + doNull(item.billtype) + "</td>";
                str += "<td>" + doNull(item.totalprice) + "</td>";
                str += "<td></td>";
                str += "<td></td>";

                str += "<td>" + doNull(item.billstartdate) + "-" + doNull(item.billenddate) + "</td>";
                str += "<td>" + doNull(item.companyid) + "</td>";
                str += "<td>" + doNull(item.basefee) + "</td>";
                str += "<td>" + doNull(item.area) + "</td>";

                str += "<td>" + doNull(item.billtime) + "</td>";
                str += "<td>" + doNull(item.payday) + "</td>";
                if (doNull(item.status) == "待生效") {
                    str += "<td><span class='label label-info'>待生效 </span></td>";
                } else if (doNull(item.status) == "已作废") {
                    str += "<td><span class='label label-danger'>已作废 </span></td>";
                } else if (doNull(item.status) == "已生效") {
                    str += "<td><span class='label label-success'>已生效 </span></td>";
                } else {
                    str += "<td><span class='label label-primary'> </span></td>";
                }
                str += "<td>" + doNull(item.info) + "</td>";
                //str += "<td>" + doNull(item.creattime) + "</td>";

                str += "<td>&nbsp;&nbsp;";
                str += "<a href='<%=basePath%>t_contract_bill/toT_contract_billCurd?oplx=view&id=" + item.billid + "' class='text-danger'>&nbsp;&nbsp;<span class='glyphicon glyphicon-search' style='color:rgb(0, 128, 255)'></span>&nbsp;&nbsp;</a>";
                //退回或者草稿，显示提交、修改、删除 按钮
                //if(doNull(item.process_status)=="-1"||doNull(item.process_status)==""||doNull(item.process_status)=="2") {
                if (doNull(item.status) == "待生效" || doNull(item.status) == "") {
                    str += "<a href='<%=basePath%>t_contract_bill/toT_contract_billCurd?oplx=edit&id=" + item.billid + "' class='text-danger'>&nbsp;&nbsp;<span class='icon-pencil'  style='color:rgb(0, 128, 255)'></span>&nbsp;&nbsp;</a>";
                    str += "<a href='javascript:eff(" + item.billid + ",\"已生效\")' class='text-danger'>&nbsp;&nbsp; 生效 &nbsp;&nbsp;</a>";
                    str += "<a href='javascript:del(" + item.billid + ")' class='text-danger'>&nbsp;&nbsp;<span class='icon-remove' style='color:rgb(0, 128, 255)'></span></a>&nbsp;&nbsp;";
                    //if(item.process_status==null||item.process_status==""){
                    //str+="<a href='<%=basePath%>workflow/startProcess?id="+item.billid+"&key=SixProcess&returnUrl=common/showStartResult'  title='启动'><span  class='label label-primary'>启动</span></a>&nbsp;&nbsp;";

                } else if (doNull(item.status) == "已生效") {
                    str += "<a href='javascript:eff(" + item.billid + ",\"已作废\")' class='text-danger'>&nbsp;&nbsp; 作废 &nbsp;&nbsp;</a>";
                }
                if ("租金" == item.billtype) {
                    str += "<a href='<%=basePath%>t_contract_bill/toT_contract_billPrint?oplx=zujin&id=" + item.billid + "'    target='_blank' class='text-danger'>&nbsp;&nbsp;<span class='icon-print'  style='color:rgb(0, 128, 255)'>打印</span>&nbsp;&nbsp;</a>";
                } else if ("物业费" == item.billtype) {
                    str += "<a href='<%=basePath%>t_contract_bill/toT_contract_billPrint?oplx=wuyefei&id=" + item.billid + "'  target='_blank'  class='text-danger'>&nbsp;&nbsp;<span class='icon-print'  style='color:rgb(0, 128, 255)'>打印</span>&nbsp;&nbsp;</a>";
                } else if ("水费" == item.billtype) {
                    str += "<a href='<%=basePath%>t_contract_bill/toT_contract_billPrint?oplx=shuifei&id=" + item.billid + "'  target='_blank'  class='text-danger'>&nbsp;&nbsp;<span class='icon-print'  style='color:rgb(0, 128, 255)'>打印</span>&nbsp;&nbsp;</a>";
                } else if ("电费" == item.billtype) {
                    str += "<a href='<%=basePath%>t_contract_bill/toT_contract_billPrint?oplx=dianfei&id=" + item.billid + "'  target='_blank'  class='text-danger'>&nbsp;&nbsp;<span class='icon-print'  style='color:rgb(0, 128, 255)'>打印</span>&nbsp;&nbsp;</a>";
                }

                str += "</td>";
                str += "</tr>";
                $("#grid_body").append(str);
                //alert("grid_body="+str);
            });//end each data;

            //汇总统计数据
            var tongji ="<tr><td></td>";
            tongji += "<td>汇总：</td><td></td><td></td><td></td><td></td>";
            tongji += "<td></td><td></td><td>"+zdjrTotal.toFixed(2)+"</td><td>"+ssjeTotal.toFixed(2)+"</td><td>"+xsjeTotal.toFixed(2)+"</td>";
            tongji += "<td></td><td></td><td></td><td>"+zmjTotal.toFixed(2)+"</td><td></td>";
            tongji += "<td></td><td></td><td></td><td></td>";
            tongji +="</tr>";
            $("#grid_body").append(tongji);

            //2、分业处理
            var element = $("#grid_paging");
            if (data.totalCount > 0) {
                //第二种处理分页方案，直接生成分页html内容，然后.html()到目标对象；
                var pageHtml = "";
                pageHtml += '<li><button type="button" class=" btn btn-primary btn-sm " onclick="Search(' + data.firstIndex + ')">首页</button></li>';
                pageHtml += '<li><button type="button" class=" btn btn-primary btn-sm " onclick="Search(' + data.previousIndex + ')">上一页</button></li>';
                pageHtml += '<li><button type="button" class=" btn btn-primary btn-sm " >当前第  ' + data.currentPageNo + ' 页</button></li>';
                pageHtml += '<li><button type="button" class=" btn btn-primary btn-sm " onclick="Search(' + data.nextIndex + ')">下一页</button></li>';
                pageHtml += '<li><button type="button" class=" btn btn-primary btn-sm " onclick="Search(' + data.lastIndex + ')">尾页</button></li>';
                element.html(pageHtml);
            } else {
                element.html("");
            }
        })//end getJSON;
    }

    //通过选择单条记录，点击‘修改‘按钮进行查看
    function toEdits() {
        var id = checkfunctionIDS(); //如果选择多条记录，则提示请选择一条记录。
        if (id != false) {
            self.location = "<%=basePath%>t_contract_bill/toT_contract_billCurd?oplx=edit&id=" + id + "&time=" + Math.random();
        }
    }

    //通过选择单条记录，点击‘查看‘按钮进行查看
    function toViews() {
        var id = checkfunctionIDS(); //如果选择多条记录，则提示请选择一条记录。
        if (id != false) {
            self.location = "<%=basePath%>t_contract_bill/toT_contract_billCurd?oplx=view&id=" + id + "&time=" + Math.random();
            ;
        }
    }

    //通过选择单条记录，点击‘删除‘按钮进行查看
    function getDel() {
        var id = checkfunctionIDS(); //如果选择多条记录，则提示请选择一条记录。
        if (id != false) {
            del(id);
        }
    }

    //生效or失效函数
    function eff(id, status) {
        var url = "<%=basePath%>t_contract_bill/effT_contract_bill?id=" + id + "&status=" + status + "&time=" + Math.random();
        bootbox.confirm({
            size: 'small',
            buttons: {
                confirm: {
                    label: ' 确定 ',
                    className: 'btn btn-sm btn-danger'
                },
                cancel: {
                    label: '   取消     ',
                    className: 'btn btn-success btn-sm'
                }
            },
            message: '您确认要生效/失效除选中的记录？',
            callback: function (result) {
                if (result) {
                    if (result) {
                        myEffect(url);
                    }
                }
            },
            title: '生效/失效记录提示：',
            className: ' '
        })
    }

    //删除函数
    function del(id) {
        var url = "<%=basePath%>t_contract_bill/delT_contract_bill?id=" + id + "&time=" + Math.random();
        bootbox.confirm({
            size: 'small',
            buttons: {
                confirm: {
                    label: ' 删除 ',
                    className: 'btn btn-sm btn-danger'
                },
                cancel: {
                    label: '   取消     ',
                    className: 'btn btn-success btn-sm'
                }
            },
            message: '您确认要删除选中的记录？',
            callback: function (result) {
                if (result) {
                    if (result) {
                        myDel(url);
                    }
                }
            },
            title: '删除记录提示：',
            className: ' '
        })
    }
</script>
